package com.wiloon.java8x.basic;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Duration;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

/*
 * Created by roy on 7/25/17;
 */
public class DateTimeX {
    public static void main(String[] args) {

    }

    public void test05(){
        Date date = new Date();
        date.setTime(1523868426000l);
        System.out.println("date:" + date);
    }
    public void test0() {
        Calendar calendar = Calendar.getInstance();
        System.out.println(calendar.get(Calendar.MONTH));
        System.out.println(calendar.get(Calendar.DATE));

        LocalDateTime localDateTime = LocalDateTime.now();
        System.out.println(localDateTime.getMonthValue());
        System.out.println(localDateTime.getDayOfMonth());
    }

    public void test() {
        long ms = 1420070421000l;
        Instant instant = Instant.ofEpochMilli(ms);
        System.out.println(instant);

        LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, ZoneId.of("UTC+8"));
        System.out.println(localDateTime);

        Date date = new Date(ms);
        System.out.println(date);


        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
        df.setTimeZone(TimeZone.getTimeZone("UTC"));
        try {
            System.out.println(df.parse("2017-07-25T04:30:48Z").toString());
        } catch (ParseException e) {
            e.printStackTrace();
        }

        Duration d = Duration.ofMinutes(3);
        System.out.println(d.getSeconds());

        Duration dz = Duration.ZERO;

        System.out.println(dz.compareTo(d));
    }
}
